package ${packagePath};

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public interface BaseAssembler {

    /**
     * 转化对象
     * @param source
     * @param targetCls
     * @param ignoreProperties
     * @param <S>
     * @param <T>
     * @return
     */
    static <S,T> T toTarget(S source, Class<T> targetCls, String... ignoreProperties) {
        T targetObj = BeanUtils.instantiateClass (targetCls);
        BeanUtils.copyProperties (source,targetObj,ignoreProperties);
        return targetObj;
    }

    /**
     * 转化对象
     * @param source
     * @param target
     * @param ignoreProperties
     * @param <S>
     * @param <T>
     * @return
     */
    static <S,T> T toTarget(S source, T target, String... ignoreProperties){
        BeanUtils.copyProperties (source,target,ignoreProperties);
        return target;
    }

    /**
     * 转化列表对象
     * @param list
     * @param tClass
     * @param ignoreProperties
     * @param <S>
     * @param <T>
     * @return
     */
    static  <S,T> List<T> toListTarget(List<S> list, Class<T> tClass, String... ignoreProperties) {
        if(list == null || list.isEmpty ()){
            return new ArrayList ();
        }
        return list.stream().map (source -> toTarget (source,tClass,ignoreProperties)).collect (Collectors.toList ());
    }

}